﻿//
// Created by Administrator on 2022/6/15.
//

#include "MainFrame.h"
#include "NotificationIcon.h"
//#include "resource.h"

#include <wx/utils.h>
#include <wx/wx.h>
//#include <wx/msw/wx.rc>

const int MainFrame::FileMenuQuitID = wxNewId();

const wxString MainFrame::FileMenuLabel = _("&File");
const wxString MainFrame::FileMenuQuitLabel = _("E&xit");
//工作目录
const wxString MainFrame::ApplicationIconFile = wxT("game.png");


MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
    : wxFrame(nullptr, -1, title, pos, size ){

    CreateMenu();
    wxImage::AddHandler ( new wxPNGHandler );
    bool v = applicationIcon.LoadFile(ApplicationIconFile);
    wxBitmap logo(wxT("MyBitmapName"), wxBITMAP_TYPE_BMP_RESOURCE);
    //create the taskbar
    notification = new NotificationIcon();
    notification->SetMainFrame(this);
    wxIcon icon( wxT("logo") );
    notification->SetIcon( icon );
}

wxMenu* MainFrame::CreateMenu(){
    auto *menu = new wxMenu;

    menu->AppendSeparator();
    menu->Append(FileMenuQuitID, FileMenuQuitLabel);

    auto *menuBar = new wxMenuBar;
    menuBar->Append(menu, FileMenuLabel);

    SetMenuBar(menuBar);
    return menu;
}

void MainFrame::OnClose(wxCloseEvent& event){
    //Destroy();
    if(event.CanVeto()){
        Show(false);
        event.Veto();
        //return;
        //event.Skip();
    }
    //notification->RemoveIcon();
    Destroy();
}

void MainFrame::OnQuit(wxCommandEvent& (event)){
    //Close(false );
    //PostMessage((HWND__ *)this->GetHandle(),WM_CLOSE,0,0);
    if ( wxMessageBox(wxT("确定要退出吗"), wxT("请确认"),
                      wxICON_QUESTION | wxYES_NO) == wxYES ){
        ExitProcess( 0 );
    }
}

BEGIN_EVENT_TABLE(MainFrame, wxFrame)
                EVT_CLOSE(MainFrame::OnClose)
                EVT_MENU(FileMenuQuitID, MainFrame::OnQuit)
END_EVENT_TABLE()